package com.gcsoftware.web.mapper.providers;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by qs on 2018/3/25.
 */
public class GwVerifyProvider {
    public String queryForList(@Param(value = "c_VERIFY_TYPE") String c_VERIFY_TYPE, @Param(value = "c_VERIFY_STATUS") String c_VERIFY_STATUS) {
        String sql = "SELECT " +
                "vt.C_DICT_ITEM_NAME C_VERIFY_TYPE_NAME,vs.C_DICT_ITEM_NAME C_VERIFY_STATUS_NAME,usr.C_LOGIN_NAME C_SUBMIT_USER, " +
                "com.c_COMPANY_ID,com.C_COMPANY_NAME, " +
                "vri.C_VERIFY_ID,C_VERIFY_STATUS,C_VERIFY_TYPE,C_VERIFY_REMARK,app.C_APP_NAME , itf.C_INTERF_NAME ,to_char(vri.D_CREATE_TIME , 'yyyy-MM-dd hh24:mi:ss') c_CREATE_TIME " +
                "FROM T_GW_VERIFY vri LEFT JOIN T_GW_APPS app ON app.C_APP_ID = vri.C_APP_ID " +
                "LEFT JOIN T_GW_INTERFS itf ON itf.C_INTERF_ID = vri.C_INTERF_ID, " +
                "t_com_sys_dictitem vs ,t_com_sys_dictitem vt , t_com_sys_user usr,t_gw_company com " +
                "WHERE vri.C_VERIFY_TYPE = vt.c_DICT_ITEM_VALUE AND vt.c_DICT_GROUP_VALUE='GRP_VERIFY_TYPES' " +
                "AND vri.C_VERIFY_STATUS = vs.c_DICT_ITEM_VALUE AND vs.c_DICT_GROUP_VALUE='GRP_VERIFY_STATUS' " +
                "AND usr.C_USER_ID = vri.C_SUBMIT_USER_ID " +
                "AND usr.C_COMPANY_ID = com.C_COMPANY_ID ";
        if (StringUtils.isNotBlank(c_VERIFY_TYPE)) {
            sql += " AND c_VERIFY_TYPE=#{c_VERIFY_TYPE}";
        }
        if(StringUtils.isNotBlank(c_VERIFY_STATUS)) {
            sql += " AND c_VERIFY_STATUS=#{c_VERIFY_STATUS}";
        } else {
            sql += " AND c_VERIFY_STATUS != 'VERIFY_STATUS_UNABLE'";
        }
        sql +=  "ORDER by vri.D_MODIFY_TIME DESC";
        return sql;
    }
}
